// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   RecursiveAnnotationAttributesVisitor.java

package org.springframework.core.type.classreading;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import org.apache.commons.logging.Log;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;

// Referenced classes of package org.springframework.core.type.classreading:
//			AbstractRecursiveAnnotationVisitor

class RecursiveAnnotationAttributesVisitor extends AbstractRecursiveAnnotationVisitor
{

	private final String annotationType;

	public RecursiveAnnotationAttributesVisitor(String annotationType, AnnotationAttributes attributes, ClassLoader classLoader)
	{
		super(classLoader, attributes);
		this.annotationType = annotationType;
	}

	public final void visitEnd()
	{
		try
		{
			Class annotationClass = classLoader.loadClass(annotationType);
			doVisitEnd(annotationClass);
		}
		catch (ClassNotFoundException ex)
		{
			logger.debug("Failed to class-load type while reading annotation metadata. This is a non-fatal error, but certain annotation metadata may be unavailable.", ex);
		}
	}

	protected void doVisitEnd(Class annotationClass)
	{
		registerDefaultValues(annotationClass);
	}

	private void registerDefaultValues(Class annotationClass)
	{
		if (Modifier.isPublic(annotationClass.getModifiers()))
		{
			Method annotationAttributes[] = annotationClass.getMethods();
			Method amethod[] = annotationAttributes;
			int j = amethod.length;
			for (int k = 0; k < j; k++)
			{
				Method annotationAttribute = amethod[k];
				String attributeName = annotationAttribute.getName();
				Object defaultValue = annotationAttribute.getDefaultValue();
				if (defaultValue == null || attributes.containsKey(attributeName))
					continue;
				if (defaultValue instanceof Annotation)
					defaultValue = AnnotationAttributes.fromMap(AnnotationUtils.getAnnotationAttributes((Annotation)defaultValue, false, true));
				else
				if (defaultValue instanceof Annotation[])
				{
					Annotation realAnnotations[] = (Annotation[])(Annotation[])defaultValue;
					AnnotationAttributes mappedAnnotations[] = new AnnotationAttributes[realAnnotations.length];
					for (int i = 0; i < realAnnotations.length; i++)
						mappedAnnotations[i] = AnnotationAttributes.fromMap(AnnotationUtils.getAnnotationAttributes(realAnnotations[i], false, true));

					defaultValue = mappedAnnotations;
				}
				attributes.put(attributeName, defaultValue);
			}

		}
	}
}
